/**
 * <p>Copyright: Copyright (c) 2014</p>
 * <p>Company: ---Technology Co. Ltd</p>
 * <p>2014-4-30</p>
 * @author Jan.Zhang
 */
package com.xianl.busiplat.dwz;

import java.util.ArrayList;
import java.util.List;


/** 
 * desc:
 * <p>author: Jan.Zhang </p>
 * date: 2014-4-30
 */
public class Page {
	
	public final static String ORDER_DIRECTION_ASC = "ASC"; 
	public final static String ORDER_DIRECTION_DESC = "DESC";
	
	private static final int DEFAULT_PAGE_SIZE = 10;
	
	private int plainPageNum = 1;
	
	private int pageNum = 1;
	private int numPerPage = DEFAULT_PAGE_SIZE;
	private String orderField = "";
	private String orderDirection = ORDER_DIRECTION_DESC;
	
	private int totalPage = 1;
	
	private int prePage = 1;
	
	private int nextPage = 1;
	
	private int totalCount = 0;
	
	private List results = new ArrayList();
	
	public int getPageNum() {
		if (pageNum > totalPage) {
			pageNum = totalPage;
		}
		return pageNum;
	}
	
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum > 0 ? pageNum : 1;
		this.plainPageNum = this.pageNum;
	}
	
	public int getNumPerPage() {
		return numPerPage;
	}
	
	public void setNumPerPage(int numPerPage) {
		this.numPerPage = numPerPage > 0 ? numPerPage : 10;
	}
	
	public String getOrderField() {
		return orderField;
	}
	
	public void setOrderField(String orderField) {
		this.orderField = orderField;
	}
	
	public String getOrderDirection() {
		return orderDirection;
	}

	public void setOrderDirection(String orderDirection) {
		this.orderDirection = orderDirection;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getPrePage() {
		prePage = pageNum - 1;
		if (prePage < 1) {
			prePage = 1;
		}
		return prePage;
	}

	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}

	public int getNextPage() {
		nextPage = pageNum + 1;
		if (nextPage > totalPage) {
			nextPage = totalPage;
		}
		
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
		totalPage = (int)(totalCount - 1) / this.numPerPage + 1;
	}

	public int getPlainPageNum() {
		return plainPageNum;
	}

	public void setPlainPageNum(int plainPageNum) {
		this.plainPageNum = plainPageNum;
	}

	
	/**
	 * @return the results
	 */
	public List getResults() {
		return results;
	}

	
	/**
	 * @param results the results to set
	 */
	public void setResults(List results) {
		this.results = results;
	}
	
}
